package com.edu.exam.enums;

/**
 * 题目附件状态枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum QuestionAttachmentStatus {

    /**
     * 上传中
     */
    UPLOADING("UPLOADING", "上传中"),

    /**
     * 可用
     */
    ACTIVE("ACTIVE", "可用"),

    /**
     * 处理中
     */
    PROCESSING("PROCESSING", "处理中"),

    /**
     * 错误
     */
    ERROR("ERROR", "错误"),

    /**
     * 禁用
     */
    DISABLED("DISABLED", "禁用");

    private final String code;
    private final String description;

    QuestionAttachmentStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 从代码创建枚举实例
     *
     * @param code 枚举代码
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 如果代码不存在
     */
    public static QuestionAttachmentStatus fromCode(String code) {
        for (QuestionAttachmentStatus status : QuestionAttachmentStatus.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("未知的题目附件状态代码: " + code);
    }

    /**
     * 从描述创建枚举实例
     *
     * @param description 枚举描述
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 如果描述不存在
     */
    public static QuestionAttachmentStatus fromDescription(String description) {
        for (QuestionAttachmentStatus status : QuestionAttachmentStatus.values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("未知的题目附件状态描述: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}